Page({
  onShareAppMessage() {
    return {
      title: 'form',
      path: 'page/component/pages/form/form'
    };
  },
  data: {
    pickerHidden: true,
    chosen: '',
  },
  pickerConfirm(e) {
    this.setData({
      pickerHidden: true
    });
    this.setData({
      chosen: e.detail.value
    });
  },

  pickerCancel() {
    this.setData({
      pickerHidden: true
    });
  },

  pickerShow() {
    this.setData({
      pickerHidden: false
    });
  },

  formSubmit(e) {
    if (e.detail.value.input != '') {
      const userId = wx.getStorageSync('userId');
      const content = e.detail.value.input;
      const date = new Date();
      const note_year = date.getFullYear();
      const note_month = date.getMonth() + 1;
      const note_day = date.getDate();

      wx.request({
        url: 'http://127.0.0.1:3001/addNote',
        method: 'POST',
        data: {
          userId,
          content,
          note_year,
          note_month,
          note_day
        },
        success: (res) => {
          console.log('笔记保存成功:', res.data);
        },
        fail: (err) => {
          console.error('笔记保存失败:', err);
        }
      });
    }
    wx.switchTab({
      url: '../account/account' // 目的页面url
    });
  },

  formReset() {
    this.setData({
      chosen: ''
    });
  }
});